#include "stdio.h"
#include "string.h"

void main()
{
	int tt[110];
	int pt,n;
	int out;
	int i,j;



	scanf("%d",&n);
	while (n!=0)
	{
		memset(tt,0,sizeof(tt));
		for (i=1;i<=n;i++) tt[i]=n-i+1;
		pt=1;
		out=0;
		for (i=1;i<=n;i++)
		{
			scanf("%d",&j);
			if (pt<=n)
			{
				if (j>=tt[pt]) pt++;
				else
                                {
					while (tt[pt]!=j) pt++;
					pt++;
				}


			}
			else out++;



		}


		printf("%d\n",out);
		scanf("%d",&n);
	}


}